#!/bin/bash
base_name=`pwd|xargs basename`
if [ $base_name != 'ts' ]
then
    echo '请在项目根目录执行'
    exit 1
fi

# check env
check_py=`which python3|wc -l`
if [ $check_py -eq 0 ]
then
    check_py=`which python|wc -l`
    if [ $check_py -eq 0 ]
    then
        echo '先安装python3'
        exit 1
    fi
    py_major_version=`python --version|awk '{print $2}'|awk -F'.' '{print $1}'`
    if [ $py_major_version -le 3 ]
    then
        echo '先安装python3'
        exit 1
    fi
fi
chmod +x ts.py

check_node=`which node|wc -l`
if [ $check_node -eq 0 ]
then
    echo '先安装node js'
    exit 1
fi

base_dir=/usr/local/ts

if [ ! -d $base_dir ]
then
    mkdir -p $base_dir
fi



/usr/bin/install sign.js $base_dir
/usr/bin/install ts.py /usr/bin/ts

check_ts=`which ts|wc -l`
if [ $check_ts -ne 1 ]
then
    echo 'install fail'
fi

